#include "mseat.h"

#include <QPainter>

QImage MSeat::img_player;
QImage MSeat::img_unknow;
QImage MSeat::img_evil;


MSeat::MSeat(QGraphicsItem *parent) :
    QGraphicsWidget(parent)
{
    counter = new MCounter;
    reset();
    if (img_evil.isNull())
        img_evil.load("../res/evil.png");

    if (img_player.isNull())
        img_player.load("../res/player.png");

    if (img_unknow.isNull())
        img_unknow.load("../res/unknown.png");

    counter = new MCounter(this);
    counter->setPos(0, 36);
}

void MSeat::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
    if (unknow)
    {
        p->drawImage(-img_unknow.width() / 2, -img_unknow.height() / 2, img_unknow);
        return;
    }

    if (evil)
    {
        p->drawImage(-img_evil.width() / 2, -img_evil.height() / 2, img_evil);
    }
    else
        p->drawImage(-img_player.width() / 2, -img_player.height() / 2, img_player);

    if (current)
    {
        QPen q;
        q.setWidth(8);
        q.setColor(QColor(255, 0, 0));
        p->setPen(q);
        p->drawEllipse(-22, -22, 44, 44);
    }

}

void MSeat::updateCounter(int num)
{
    counter->setNumber(num);
}


void MSeat::setEvil(bool is_evil)
{
    evil = is_evil;
    unknow = false;
    update();
}

void MSeat::reset()
{
    unknow = true;
    current = false;
    counter->setNumber(-1);
    update();
}

void MSeat::setCurrent(bool is_current)
{
    current = is_current;
}
